package cn.ycbjie.ycaudioplayer.ui.study.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.viewHolder.BaseViewHolder;


import cn.ycbjie.ycaudioplayer.R;
import cn.ycbjie.ycaudioplayer.ui.study.model.VideoPlayerFavorite;


public class NarrowImageAdapter extends RecyclerArrayAdapter<VideoPlayerFavorite> {


    public NarrowImageAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new NarrowImageViewHolder(parent);
    }

    private static class NarrowImageViewHolder extends BaseViewHolder<VideoPlayerFavorite> {

        ImageView img_cainixihuan;
        TextView tv_cainixihuan;
        NarrowImageViewHolder(ViewGroup parent) {
            super(parent, R.layout.view_audio_player_favorite);
//            img_cainixihuan=$(R.id.img_cainixihuan);
            img_cainixihuan=$(R.id.img_cainixihuan);
            tv_cainixihuan = $(R.id.tv_cainixihuan);
        }

        @Override
        public void setData(VideoPlayerFavorite data) {
            String uri = data.getLogoUrl();
            if(uri.startsWith("https")) {
                uri = uri.substring(0, 4) + uri.substring(5, uri.length());
            }
            Glide.with(getContext())
                    .load(uri)
                    .into(img_cainixihuan);
            tv_cainixihuan.setText(data.getTitle());
        }
    }
}
